import user.ProxyUser;
import user.User;
import user.factory.AdminUserFactory;
import user.factory.NormalUserFactory;
import utils.SingletonScanner;

import java.util.Scanner;

public class LibrarySystem {
    private Scanner scanner = SingletonScanner.getScanner();

    public static void main(String[] args) {
        AdminUserFactory adminUserFactory = new AdminUserFactory();
        User AdminUser1 = adminUserFactory.createUser(1, "ben");

        NormalUserFactory normalUserFactory = new NormalUserFactory();
        User NormalUser1 = normalUserFactory.createUser(2, "kay");
        User NormalUser2 = normalUserFactory.createUser(3, "Liam");

        ProxyUser proxyUser1 = new ProxyUser(AdminUser1);
        ProxyUser proxyUser2 = new ProxyUser(NormalUser1);
        ProxyUser proxyUser3 = new ProxyUser(NormalUser2);

        LibrarySystem librarySystem = new LibrarySystem();
        ProxyUser currentUser = librarySystem.selectRole(proxyUser1, proxyUser2, proxyUser3);
        while (true){
            int choice = currentUser.display();
            currentUser.operation(choice);
        }

    }

    public ProxyUser selectRole(ProxyUser AdminUser1, ProxyUser NormalUser1, ProxyUser NormalUser2){
        ProxyUser proxyUser = null;
        System.out.println("******图书管理系统******");
        System.out.println("请选择角色登录:");
        System.out.println("1. 管理员");
        System.out.println("2. 普通用户(kay)");
        System.out.println("3. 普通用户(Liam)");
        System.out.println("4. 退出系统");
        System.out.println("**********************");

        int choice = scanner.nextInt();

        switch (choice){
            case 1:
                proxyUser = AdminUser1;
                break;
            case 2:
                proxyUser = NormalUser1;
                break;
            case 3:
                proxyUser = NormalUser2;
                break;
            case 4:
                System.out.println("退出系统");
                System.exit(0);
                break;
        }

        return proxyUser;
    }


}
